#!/bin/sh

mosquitto_sub -h 172.24.42.2 -R -t 'tele/+/sens/#' -F "%t %p %U" | while read TOPIC VALU EPOCH; do
	SEPOCH=$(echo $EPOCH|sed -e 's/\.//g'|cut -b -13)
	LEPOCH=$(date +%s%N|cut -b -13)
	TOPI=$(echo $TOPIC|sed -e 's/tele/sp/g')
	IVAL=$(echo $VALU|cut -d\. -f1)
	echo "insert into datain (time,sensortime,topic,value) values ($LEPOCH,$SEPOCH,'$TOPI',$IVAL);"|mysql -t Sensor
	echo "insert into datain (time,sensortime,topic,value) values ($LEPOCH,$SEPOCH,'$TOPI',$IVAL);"
done
	
